#ifndef DAHENGCAMERADEVICE_H
#define DAHENGCAMERADEVICE_H

#include <QObject>
#include "device.h"
#include "GxIAPI.h"
#include "DxImageProc.h"
#include "../video/GXBitmap.h"

class DahengCameraDevice : public Device
{
    Q_OBJECT
public:
    static void InitLib();
    static void UninitLib();

    explicit DahengCameraDevice(QObject *parent = nullptr);

    DahengCameraDevice(QWidget* pWidget,QString ip);

    virtual Device* clone(Device* pDevice) override;

    virtual void writeXML(QXmlStreamWriter &writer) override;
    virtual void readFromXML(QXmlStreamReader &reader) override;

    virtual int initDevice() override;
    virtual void writeData(const QVariant &data) override;
    virtual void uninitDevice() override;

    virtual QString getClassName() override;

    int     OpenCamera();
    int     ReadCameraParameter();
    int     InitCamera();
    int     ConfigureCamera();
    int     AcquisitionStart();
    int     AcquisitionStop();
    int     UnconfigureCamera();
    int     SnapImage();
    int     UninitCamera();
    int     CloseCamera();
    void    writeBmpFile(char *data, int w, int h,int imageNum = 0);

signals:
    void    finishSnapImage(int index);

public:
    QString             GetIP(){return m_strIP;}
    void                SetIP(QString strIP){m_strIP = strIP;}

    QString             GetMAC(){return m_strMAC;}
    void                SetMAC(QString strMAC){m_strMAC = strMAC;}

    QString             GetCameraName(){return m_strCameraName;}
    void                SetCameraName(QString strCameraName){m_strCameraName = strCameraName;}

    int                 GetPort(){return m_nPort;}
    void                SetPort(int nPort){m_nPort = nPort;}

    int                 SetViedoWidget(QWidget* pWidget);
    GX_DEV_HANDLE       GetDeviceHandle(){return m_hDevice;}

private:
    QString             m_strVendorName;
    QString             m_strDeviceModel;
    QString             m_strSerialNumber;
    QString             m_strUserID;

public:
    QString             GetVendorName(){return m_strVendorName;}
    QString             GetDeviceModel(){return m_strDeviceModel;}
    QString             GetSerialNumber(){return m_strSerialNumber;}
    QString             GetUserID(){return m_strUserID;}

private:
    GX_STATUS           m_emStatus;
    GX_DEV_HANDLE       m_hDevice;
    GX_DS_HANDLE        m_hStream;              ///< 设备流句柄
    GX_FRAME_DATA       m_stFrameData;          ///< GetImage获取的图像地址
    GX_OPEN_PARAM       m_stOpenParam;
    HWND                m_hWidgetCamera;

    QString             m_strIP;
    QString             m_strMAC;
    QString             m_strCameraName;
    int                 m_nPort;

private:
    CGXBitmap           *m_pBitmap;
    QWidget             *m_pWidget;
};

#endif // DAHENGCAMERADEVICE_H
